package com.fc.test.service;

import java.util.List;
import java.util.Arrays;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import cn.hutool.core.util.StrUtil;
import com.fc.test.common.base.BaseService;
import com.fc.test.common.support.ConvertUtil;
import com.fc.test.mapper.auto.AdminMapper;
import com.fc.test.model.auto.Admin;
import com.fc.test.model.auto.AdminExample;
import com.fc.test.model.custom.Tablepar;
import com.fc.test.util.SnowflakeIdWorker;
import com.fc.test.util.StringUtils;

/**
 * 管理员用户信息 AdminService
 * @Title: AdminService.java 
 * @Package com.fc.test.service 
 * @author DrRic_自动生成
 * @email drhyz@qq.com
 * @date 2020-07-05 17:22:19  
 **/
@Service
public class AdminService implements BaseService<Admin, AdminExample>{
	@Autowired
	private AdminMapper adminMapper;
	
      	   	      	      	      	      	      	      	
	/**
	 * 分页查询
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	 public PageInfo<Admin> list(Tablepar tablepar,Admin record){
	        AdminExample testExample=new AdminExample();
	        testExample.createCriteria().andLikeQuery(record);
	        testExample.setOrderByClause("aid ASC");
			if(StrUtil.isNotEmpty(tablepar.getOrderByColumn())) {
	        	testExample.setOrderByClause(StringUtils.toUnderScoreCase(tablepar.getOrderByColumn()) +" "+tablepar.getIsAsc());
	        }
	        PageHelper.startPage(tablepar.getPageNum(), tablepar.getPageSize());
	        List<Admin> list= adminMapper.selectByExample(testExample);
	        PageInfo<Admin> pageInfo = new PageInfo<Admin>(list);
	        return  pageInfo;
	 }

	@Override
	public int deleteByPrimaryKey(String ids) {
					
			Integer[] integers = ConvertUtil.toIntArray(",", ids);
			List<Integer> stringB = Arrays.asList(integers);
			AdminExample example=new AdminExample();
			example.createCriteria().andAidIn(stringB);
			return adminMapper.deleteByExample(example);
			
				
	}
	
	
	@Override
	public Admin selectByPrimaryKey(String id) {
				
			Integer id1 = Integer.valueOf(id);
			return adminMapper.selectByPrimaryKey(id1);
				
	}

	
	@Override
	public int updateByPrimaryKeySelective(Admin record) {
		return adminMapper.updateByPrimaryKeySelective(record);
	}
	
	
	/**
	 * 添加
	 */
	@Override
	public int insertSelective(Admin record) {
				
		record.setAid(null);
		
				
		return adminMapper.insertSelective(record);
	}
	
	
	@Override
	public int updateByExampleSelective(Admin record, AdminExample example) {
		
		return adminMapper.updateByExampleSelective(record, example);
	}

	
	@Override
	public int updateByExample(Admin record, AdminExample example) {
		
		return adminMapper.updateByExample(record, example);
	}

	@Override
	public List<Admin> selectByExample(AdminExample example) {
		
		return adminMapper.selectByExample(example);
	}

	
	@Override
	public long countByExample(AdminExample example) {
		
		return adminMapper.countByExample(example);
	}

	
	@Override
	public int deleteByExample(AdminExample example) {
		
		return adminMapper.deleteByExample(example);
	}
	
	/**
	 * 检查name
	 * @param admin
	 * @return
	 */
	public int checkNameUnique(Admin admin){
		AdminExample example=new AdminExample();
		example.createCriteria().andRoleEqualTo(admin.getRole());
		List<Admin> list=adminMapper.selectByExample(example);
		return list.size();
	}


}
